package com.bocai.dahuatech.utils;

import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.bocai.dahuatech.Bean.BaseBean;
import com.bocai.dahuatech.Bean.IndividualBean;
import com.bocai.dahuatech.R;
import com.bocai.dahuatech.netutil.MyRetrofit;
import com.bocai.dahuatech.ui.activity.RegistDistributorSecendActivity;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by admin on 2016/3/29.
 */
public class RZUtil {

    public static void renZheng(final Context context)
    {
        new MyRetrofit().getGirlApi().checkCompanyName(SharePrefencesUtil.getCompanyName(context),SharePrefencesUtil.gettel(context))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseBean>() {
                    @Override
                    public void onCompleted()
                    {
                    }

                    @Override
                    public void onError(Throwable e)
                    {
                        Toast.makeText(context,R.string.neterror,Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onNext(BaseBean baseBean)
                    {
                        if(baseBean.getReturnNo().equals("1"))
                        {
                            String result=AESUtils.decode(baseBean.getContent());
                            if("1".equals(result.toLowerCase()))
                            {
                                Intent intent=new Intent(context,RegistDistributorSecendActivity.class);
                                IndividualBean bean=new IndividualBean();
                                intent.putExtra("register",bean);
                                intent.putExtra("what", "certifiled");
                                context.startActivity(intent);
                            }else if("2".equals(result.toLowerCase()))
                            {
                                DialogUtil.dialogForOneButton(context,R.string.alreadysubmittologin, R.string.know);
                            }else if("3".equals(result.toLowerCase()))
                            {
                                Toast.makeText(context,"您注册的手机号重复，请修改手机号",Toast.LENGTH_SHORT).show();
                            }
                        }else
                        {
                            Toast.makeText(context,baseBean.getReturnInfo(),Toast.LENGTH_SHORT).show();
                        }
                    }
                });
    }
}
